from rest_framework import viewsets, status
from rest_framework.permissions import (
    IsAuthenticatedOrReadOnly, AllowAny, SAFE_METHODS
)
from rest_framework.decorators import action
from rest_framework.response import Response

from .models import User
from .serializers import (
    UserSerializer, UserDetailSerializer
)
from .filters import UserFilter


class UserViewSet(viewsets.ModelViewSet):
    serializer_class = UserSerializer
    queryset = User.objects.filter(is_active=True)
    permission_classes = [AllowAny]
    filter_class = UserFilter

    def retrieve(self, request, *args, **kwargs):
        self.serializer_class = UserDetailSerializer
        self.permission_classes = [IsAuthenticatedOrReadOnly]
        return super().retrieve(request, *args, **kwargs)
